package com.ymatou.iapi.sellercs.testcase;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ymatou.iapi.im.parameter.GetMessageListAndSessionByTimelineBean;
import com.ymatou.iapi.im.parameter.SendCommentBean;
import com.ymatou.iapi.sellercs.parameter.CsSessionDetail;
import com.ymatou.iapi.sellercs.parameter.SellerSendMessageBean;
import com.ymatou.iapi.sellercs.parameter.SendMessageBean;
import com.ymatou.iapi.sellercs.parameter.SendMessageResp;
import com.ymatou.iapi.sellercs.service.SellerSendMessageCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.business.service.ImCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.model.YmtCssession;
import com.ymttest.database.model.YmtMessage;
import com.ymttest.database.model.YmtQueuesession;
import com.ymttest.database.redis.ImRedisWapper;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

import redis.clients.jedis.Tuple;
/**
*SellerSendMessage
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SellerSendMessage{
	private static SellerSendMessageBean sellersendmessageBean;
	private static SellerSendMessageCall sellersendmessageCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static String sellername = EnvSetup.getData("autotest_sellerName1");
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("SellerSendMessage");
	}

	@Before
	public void caseUp() throws ClientProtocolException, IOException {
		sellersendmessageBean=new SellerSendMessageBean();
		sellersendmessageCall=new SellerSendMessageCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
		SellerCSIMCallService.OffLine(sellerId, null);
		SellerCSIMCallService.OffLine(zsellerId, null);
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(sellersendmessageCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	/**
	 * @param SendMessageBean
	 * @param type <br>0 ymt_queuesession <br>1 ymt_cssession 不在线的时候0 在线1
	 *  * @param unReadCount 期望的未读消息数量
	 * @throws InterruptedException 
	 */
	private void verifyDB(SellerSendMessageBean SendMessageBean,Integer unReadCount) throws InterruptedException{
			 YmtCssession info = YmtSellerCSIMWapper.selectYmtCssession(SendMessageBean.getMasterCSId(), SendMessageBean.getUserId()).get(0);
			Logger.debug("YmtQueuesession:"+FormatUtil.beanToGSONString(info));
			Logger.verifyNotNull(info.getBeginTime(),"验证BeginTime");
			Logger.verifyEquals(13,info.getFromPlatform(),"来源平台-固定13");
			Logger.verifyEquals(true,new Date().getTime()-info.getLastMessageTime().getTime()<10000,"LastMessageTime-误差内");
			Logger.verifyEquals(SendMessageBean.getMasterCSId(),info.getMasterCSId(),"验证MasterCSId");
			Logger.verifyNotNull(info.getSessionNumber(),"验证SessionNumber");
			Logger.verifyEquals(unReadCount,info.getUnReadCount(),"unReadCount");
		//   0 User,  1  ReAssign, 2 CS
			Logger.verifyEquals(2,info.getOpenType(),"OpenType-2分配打开会话");
			Logger.verifyEquals(null,info.getCloseType(),"CloseType-没有关闭时未设置");
			Logger.verifyEquals(0,info.getStatus(),"Status-0开启");
			Logger.verifyEquals(0,info.getMark(),"Mark-0");
	}
	private void verifyReturn(SellerSendMessageBean sendmessageBean2, SendMessageResp result,Boolean IsCancel) {
		JUserWapper JUserWapper=new JUserWapper();
		String fromurl=JUserWapper.selectUserinfoexByUid(sendmessageBean2.getMasterCSId()).get(0).getLogoUrl();
		Logger.verifyEquals(fromurl==null?JUserCallService.defaultSellerImg:fromurl,result.getFromUserLogo(),"验证FromUserLogo");
		String tourl=JUserWapper.selectUserinfoexByUid(sendmessageBean2.getUserId()).get(0).getLogoUrl();
		Logger.verifyEquals(tourl==null||tourl.length()==0?JUserCallService.defaultImg:tourl,result.getToUserLogo(),"验证ToUserLogo");
		
		String fromname=JUserWapper.selectUserinfoByUid(sendmessageBean2.getMasterCSId()).get(0).getLoginId();
		Logger.verifyEquals(fromname,result.getFromUserName(),"验证FromUserName");
		
		String toname=JUserWapper.selectUserinfoByUid(sendmessageBean2.getUserId()).get(0).getLoginId();
		Logger.verifyEquals(toname,result.getToUserName(),"验证toname");
		
		Logger.verifyEquals(0,result.getFromUserUnReadMessageCount(),"FromUserUnReadMessageCount");
		Logger.verifyEquals(0,result.getToUserUnReadMessageCount(),"ToUserUnReadMessageCount");
		Logger.verifyNotNull(result.getMessageId(),"验证msgId");
		Logger.verifyEquals(IsCancel,result.getIsCancel(),"验证IsCancel");
	}
	
	private YmtMessage verifyMessage(SellerSendMessageBean sendmessageBean2, String messageId) throws InterruptedException {
		YmtMessage msg = new ImDefaultWapper().selectImInfo(sellersendmessageCall.getResult().getMessageId()).get(0);
		Logger.debug("msg:"+FormatUtil.beanToGSONString(msg));
		Logger.verifyEquals(sendmessageBean2.getMasterCSId(),msg.getMsgFromId(),"验证MsgFromId");
		Logger.verifyEquals(sendmessageBean2.getUserId(),msg.getMsgToId(),"验证MsgToId");
		Logger.verifyEquals(sendmessageBean2.getMessage(),msg.getMessage(),"验证Message");
		
		Logger.verifyEquals(true,msg.getSessionNumber().length()>0, "验证SessionNumber非空");
		Logger.verifyIsContains(sendmessageBean2.getCsId().toString(),msg.getSessionNumber(), "验证SessionNumber");
		return msg;
	}
	private void verifyRedis(SellerSendMessageBean SendMessageBean,Integer unReadCount) throws InterruptedException, ClientProtocolException, IOException{
			ImRedisWapper ImRedisWapper=new ImRedisWapper();
			Set<Tuple> set = ImRedisWapper.getCSession(SendMessageBean.getMasterCSId());
			set.forEach(t->{Logger.debug("tuple:"+t.getScore()+":"+t.getElement());});
			List<String> list = set.stream().map(t->{return t.getElement();}).collect(Collectors.toList());
			Logger.verifyEquals(true,list.contains(SendMessageBean.getUserId().toString()),"验证QSession中包含有FromUserId");
			CsSessionDetail csSessionDetail = ImRedisWapper.getCSessionDetails(sellerId, SendMessageBean.getUserId(),sellerId);
			Logger.debug("CSessionDetails:"+FormatUtil.beanToGSONString(csSessionDetail));
			//TODO 这里没有主子账号考虑?
			Logger.verifyEquals(SendMessageBean.getCsId(),csSessionDetail.getCsId(),"验证csid");
			Logger.verifyEquals(JUserCallService.GetUserInfo(SendMessageBean.getCsId()).getLoginId(),csSessionDetail.getCsName(),"验证csname");
			Logger.verifyNotNull(csSessionDetail.getSessionId(),"验证SessionId不为空");
			Logger.verifyNotNull(csSessionDetail.getSessionNumber(),"验证SessionNumber不为空");
		
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SellerSendMessage_001() {
		Logger.start(true,"进行中会话发送消息成功");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			
			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("seller send message time:"+YMTDateUtil.getBeforeOrNextDay(0));
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();
			verifyReturn(sellersendmessageBean,sellersendmessageCall.getResult(),false);
			verifyMessage(sellersendmessageBean,sellersendmessageCall.getResult().getMessageId());
			verifyDB(sellersendmessageBean,0);
			verifyRedis(sellersendmessageBean, 0);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SellerSendMessage_002() {
		Logger.start(true,"不输入MasterCSId失败");
		try {
			int userId=1;
			sellersendmessageBean.setCsId(sellerId);
//			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("seller send message time:"+YMTDateUtil.getBeforeOrNextDay(0));
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();	
			Logger.verifyEquals("500", sellersendmessageCall.getString("Status"), "验证Status");
			//{"Status":500,"Msg":"发送消息失败","Result":{"success":false,"sendMessageResModel":null,"errorMsg":"发送消息失败"}}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SellerSendMessage_003() {
		Logger.start(true,"不输入CsId失败");
		try {
			int userId=1;
//			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("seller send message time:"+YMTDateUtil.getBeforeOrNextDay(0));
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();	
			Logger.verifyEquals("500", sellersendmessageCall.getString("Status"), "验证Status");		
			//{"Status":500,"Msg":"子客服不在线，发起会话失败","Result":{"success":false,"sendMessageResModel":null,"errorMsg":"子客服不在线，发起会话失败"}}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SellerSendMessage_004() {
		Logger.start(true,"不输入UserId失败");
		try {
			int userId=1;
			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("seller send message time:"+YMTDateUtil.getBeforeOrNextDay(0));
//			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();	
			Logger.verifyEquals("400", sellersendmessageCall.getString("Status"), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SellerSendMessage_005() {
		Logger.start(true,"不输入Message失败");
		try {
			int userId=1;
			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
//			sellersendmessageBean.setMessage("seller send message time:"+YMTDateUtil.getBeforeOrNextDay(0));
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();	
			Logger.verifyEquals("400", sellersendmessageCall.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerSendMessage_006() {
		Logger.start(true,"CSId码头客服调用码头客服csim.iapi发送消息");
		try {
			//码头客服 sellerId 固定 测试用
			Integer kfid=SellerCSIMCallService.CsimId;
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(kfid, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(5000);
			
			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("seller send message time:"+YMTDateUtil.getBeforeOrNextDay(0));
			sellersendmessageBean.setUserId(kfid);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();	
			verifyReturn(sellersendmessageBean,sellersendmessageCall.getResult(),false);
			
			verifyMessage(sellersendmessageBean,sellersendmessageCall.getResult().getMessageId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerSendMessage_007() {
		Logger.start(true,"发送消息给用户如果有且会话中客服不是当前客服，则提示占线中");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
//			SellerCSIMCallService.AppLogin(sellerId);
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			SellerCSIMCallService.AppLogin(zsellerId);
			
			sellersendmessageBean.setCsId(zsellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("seller send message time:"+YMTDateUtil.getBeforeOrNextDay(0));
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();	
			//{"Status":500,"Msg":"占线中，客服3383正在与当前客户聊天","Result":{"success":false,"sendMessageResModel":null,"errorMsg":"占线中，客服3383正在与当前客户聊天"}}
			Logger.verifyEquals("500", sellersendmessageCall.getString("Status"), "验证Status");
			Logger.verifyIsContains("占线中", sellersendmessageCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SellerSendMessage_008() {
		Logger.start(true,"没有进行中的会话发送消息成功,创建新会话");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
//			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
//			SellerCSIMCallService.SendMessage(sendmessageBean);
//			//触发分配
//			SellerCSIMCallService.Assign();
//			Thread.sleep(5000);
			
			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("seller send message time:"+YMTDateUtil.getBeforeOrNextDay(0));
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();	
			verifyReturn(sellersendmessageBean,sellersendmessageCall.getResult(),false);
			verifyMessage(sellersendmessageBean,sellersendmessageCall.getResult().getMessageId());
			verifyDB(sellersendmessageBean,0);
			verifyRedis(sellersendmessageBean, 0);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SellerSendMessage_009() {
		Logger.start(true,"进行中会话发送消息成功,消息中带有导流信息拦截");
		try {
			//加我 加微信
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			
			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("我是买手加微信:135-1234-1234");
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();
			verifyReturn(sellersendmessageBean,sellersendmessageCall.getResult(),true);
//			sellersendmessageBean.setMessage("我是买手加微信:"+YMTDateUtil.getBeforeOrNextDay(0));
//			sellersendmessageCall.callService();
//			verifyReturn(sellersendmessageBean,sellersendmessageCall.getResult(),true);
//			//Status":501,"Msg":"为了买卖双方的交易安全和体验，请勿引导至站外平台。当前消息已屏蔽！
			Logger.verifyEquals("501", sellersendmessageCall.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SellerSendMessage_010() {
		Logger.start(true,"进行中会话发送消息成功,消息中带有图片导流信息拦截");
		try {
			String fpath = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "noymt.jpg";
			TestDataManager.CreateMatrixFile("http://u.wechat.com/1.jpg", fpath);
			String turl=TestDataManager.UploadFile(fpath);
			String fpath2 = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "noymt2.jpg";
			TestDataManager.CreateMatrixFile("http://m.tb.cn/1.jpg", fpath2);
			String turl2=TestDataManager.UploadFile(fpath2);
			//加我 加微信
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			
			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("[img]"+turl+"[/img]");
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();
			Logger.verifyEquals("501", sellersendmessageCall.getString("Status"), "验证Status");
			sellersendmessageBean.setMessage("[img]"+turl2+"[/img]");
			sellersendmessageCall.callService();
			Logger.verifyEquals("501", sellersendmessageCall.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	//bug 商家给用户发消息需要带sessionnum 否则会发生过量拦截(因为全量匹配了)
	public void Tc_SellerSendMessage_011() {
		Logger.start(true,"进行中会话发送2条消息成功,消息中带有导流信息拦截,相关消息都拦截");
		try {
			//第一条为一个手机号 第二条为加我微信
			//加我 加微信
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			
			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage(TestDataManager.getPhoneNum());
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();
			
			sellersendmessageBean.setMessage("我是买手加微信");
			sellersendmessageCall.callService();
			String msgid=sellersendmessageCall.getResult().getMessageId();
			List<YmtMessage> listmsg = new ImDefaultWapper().selectImInfo(msgid);
			Logger.debug("getmsg:"+FormatUtil.beanToGSONString(listmsg));
			Logger.verifyEquals(true,listmsg.get(0).getSessionNumber().length()>0, "验证SessionNumber非空");
			Logger.verifyIsContains(userId.toString(),listmsg.get(0).getSessionNumber(), "验证SessionNumber");
			verifyReturn(sellersendmessageBean,sellersendmessageCall.getResult(),true);
//			sellersendmessageBean.setMessage("我是买手加微信:"+YMTDateUtil.getBeforeOrNextDay(0));
//			sellersendmessageCall.callService();
//			verifyReturn(sellersendmessageBean,sellersendmessageCall.getResult(),true);
//			//Status":501,"Msg":"为了买卖双方的交易安全和体验，请勿引导至站外平台。当前消息已屏蔽！
			Logger.verifyEquals("501", sellersendmessageCall.getString("Status"), "验证Status");
			Thread.sleep(2000);
			GetMessageListAndSessionByTimelineBean getMessageListAndSessionByTimelineBean = ImCallService.initGetMessageListAndSessionByTimelineBean(sellerId,userId);
			JsonObject msgs = ImCallService.GetMessageListAndSessionByTimeline(getMessageListAndSessionByTimelineBean);
			//{"Msg":"操作成功","Status":"Success","Result":{"YmtMessageSession":{"UserSessionId":"24635724_24829813","FromUserName":"autotest1","FromUserLogo":"http://staticontent.ymatou.com/app/userlogo/ms.jpg","ToUserName":"autotest3gTpOKG","ToUserLogo":"http://staticontent.ymatou.com/app/userlogo/mj.jpg","IsImportant":false,"Slient":false,"Translate":false},"YmtMessageList":[{"MessageId":"24829813_24635724_202052","MsgFromId":24829813,"MsgFrom":"autotest3gTpOKG","MsgToId":24635724,"MsgTo":"autotest1","Message":"connect","PostTime":"2019-01-10T16:47:05","LongPostTime":1547110025970,"CsId":24635724,"CsName":"autotest1","SessionNumber":"20190110164706_24635724_24829813","IsCancel":false,"MessageAttachList":[]},{"MessageId":"24635724_24829813_202053","MsgFromId":24635724,"MsgFrom":"autotest1","MsgToId":24829813,"MsgTo":"autotest3gTpOKG","Message":"13032309698","PostTime":"2019-01-10T16:47:10","LongPostTime":1547110030010,"CsId":24635724,"CsName":"autotest1","SessionNumber":"","IsCancel":false,"MessageAttachList":[]},{"MessageId":"24635724_24829813_202054","MsgFromId":24635724,"MsgFrom":"autotest1","MsgToId":24829813,"MsgTo":"autotest3gTpOKG","Message":"我是买手加微信","PostTime":"2019-01-10T16:47:10","LongPostTime":1547110030050,"CsId":24635724,"CsName":"autotest1","SessionNumber":"","IsCancel":true,"MessageAttachList":[{"Type":2,"Content":"为了买卖双方的交易安全和体验，请勿引导至站外平台。当前消息已屏蔽！"}]}]}}
			JsonArray YmtMessageList = msgs.get("Result").getAsJsonObject().get("YmtMessageList").getAsJsonArray();
			//一共发了3条消息 第一条正常 第二条，第三条应该被取消
			Logger.verifyEquals(3, YmtMessageList.size(), "期望条数");
			Logger.verifyEquals(true,YmtMessageList.get(1).getAsJsonObject().get("IsCancel").getAsBoolean(), "第二条记录被取消");
			Logger.verifyEquals(true,YmtMessageList.get(2).getAsJsonObject().get("IsCancel").getAsBoolean(), "第三条记录被取消");
			Logger.verifyEquals(2,YmtMessageList.get(2).getAsJsonObject().get("MessageAttachList").getAsJsonArray().get(0).getAsJsonObject().get("Type").getAsInt(), "第三条记录带附件Type2");
			Logger.verifyIsContains("屏蔽",YmtMessageList.get(2).getAsJsonObject().get("MessageAttachList").getAsJsonArray().get(0).getAsJsonObject().get("Content").getAsString(), "第三条记录带附件Content");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SellerSendMessage_012() {
		Logger.start(true,"进行中会话发送消息成功,消息中带有图片无导流信息不拦截");
		try {
			String fpath = System.getProperty("user.dir") + File.separator
					+ "resource" + File.separator + "noymt.jpg";
			TestDataManager.CreateMatrixFile("http://www.ymatou.com/1.jpg", fpath);
			String turl=TestDataManager.UploadFile(fpath);
			//加我 加微信
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			
			sellersendmessageBean.setCsId(sellerId);
			sellersendmessageBean.setMasterCSId(sellerId);
			sellersendmessageBean.setMessage("[img]"+turl+"[/img]");
			sellersendmessageBean.setUserId(userId);
			sellersendmessageCall.setData(sellersendmessageBean);
			sellersendmessageCall.callService();
			Logger.verifyEquals("200", sellersendmessageCall.getString("Status"), "验证Status");
			YmtMessage msg = new ImDefaultWapper().selectImInfo(sellersendmessageCall.getResult().getMessageId()).get(0);
			Logger.debug("msg:"+FormatUtil.beanToGSONString(msg));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}